package yyh.guanganmen.db;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;



public class CodingListDBServer {
	
	public List<Integer> getInhosptival_ids() throws IOException{
		DbUtil db = new DbUtil();
		Connection conn = null;
		PreparedStatement ps = null;
		String sql = "";
		ResultSet rs = null;
		List<Integer> Inhosptival_ids = new ArrayList<Integer>();
	
		try{
			conn = db.getConnection();
			sql = "select distinct t.inhosptial_id from INCASE_HERBMED t";
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery(sql);
			while(rs.next()){
				Inhosptival_ids.add(rs.getInt("inhosptial_id"));
			}
		}catch(SQLException e){
			e.printStackTrace();;
		}finally{
			db.closeConn(conn, ps, rs);
		}
		
		Collections.sort(Inhosptival_ids, new Comparator<Object>() {
			public int compare(Object obj1, Object obj2) {
				Integer One = (Integer) obj1;
				Integer Two = (Integer) obj2;
				return One - Two;
			}
		});
		return Inhosptival_ids;
	}
	
	public static void main(String[] args) throws IOException{
		CodingListDBServer c = new CodingListDBServer();
		List<Integer> list = c.getInhosptival_ids();
		for(Integer i:list){
			System.out.println(i);
		}
		
	}


}
